package com.ruoyi.project.system.aboutus.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.aboutus.domain.AboutUs;
import com.ruoyi.project.system.aboutus.service.IAboutUsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 关于我们Controller
 * 
 * @author LCL
 * @date 2021-01-21
 */
@Controller
@RequestMapping("/system/aboutus")
public class AboutUsController extends BaseController
{
    private String prefix = "system/aboutus";

    @Autowired
    private IAboutUsService aboutUsService;

    @RequiresPermissions("system:aboutus:view")
    @GetMapping()
    public String aboutus()
    {
        return prefix + "/aboutus";
    }

    /**
     * 查询关于我们列表
     */
    @RequiresPermissions("system:aboutus:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AboutUs aboutUs)
    {
        startPage();
        List<AboutUs> list = aboutUsService.selectAboutUsList(aboutUs);
        return getDataTable(list);
    }

    /**
     * 导出关于我们列表
     */
    @RequiresPermissions("system:aboutus:export")
    @Log(title = "关于我们", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AboutUs aboutUs)
    {
        List<AboutUs> list = aboutUsService.selectAboutUsList(aboutUs);
        ExcelUtil<AboutUs> util = new ExcelUtil<AboutUs>(AboutUs.class);
        return util.exportExcel(list, "aboutus");
    }

    /**
     * 新增关于我们
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存关于我们
     */
    @RequiresPermissions("system:aboutus:add")
    @Log(title = "关于我们", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AboutUs aboutUs)
    {
        return toAjax(aboutUsService.insertAboutUs(aboutUs));
    }

    /**
     * 修改关于我们
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        AboutUs aboutUs = aboutUsService.selectAboutUsById(id);
        mmap.put("aboutUs", aboutUs);
        return prefix + "/edit";
    }

    /**
     * 修改保存关于我们
     */
    @RequiresPermissions("system:aboutus:edit")
    @Log(title = "关于我们", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AboutUs aboutUs)
    {
        return toAjax(aboutUsService.updateAboutUs(aboutUs));
    }

    /**
     * 删除关于我们
     */
    @RequiresPermissions("system:aboutus:remove")
    @Log(title = "关于我们", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(aboutUsService.deleteAboutUsByIds(ids));
    }
}
